package adapters;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.List;

/**
 * Created by Administrator on 2018/5/9.
 */

public class SetViewPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> list;
    private List<String> titles;
    private LayoutInflater mInflater;
    private Context mContext;

    public SetViewPagerAdapter(FragmentManager fm, List<Fragment> list, List<String> titles, Context mContext) {
        super(fm);
        this.list = list;
        this.titles = titles;
        this.mContext=mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    public View getTabView(int position) {
        View view = mInflater.inflate(R.layout.tablayout_custom, null);
        TextView tv = (TextView) view.findViewById(R.id.tv_tablayout_custom);
        if (position > titles.size()-1) {
            tv.setText(titles.get(titles.size()-1));
        }else {
            tv.setText(titles.get(position));
        }
        ImageView img = (ImageView) view.findViewById(R.id.iv_tablayout_custom);
        if (position == 0) {
            img.setImageResource(R.mipmap.yyxxin);
            tv.setTextColor(mContext.getResources().getColor(R.color.date_bg_color));
        } else if (position == 1) {
            img.setImageResource(R.mipmap.cssz);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        } else if (position == 2){
            img.setImageResource(R.mipmap.gzbh);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        }else if (position == 3){
            img.setImageResource(R.mipmap.kbrizhiw);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        }else if (position == 4){
            img.setImageResource(R.mipmap.bbgxw);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        }else if (position == 5){
            img.setImageResource(R.mipmap.wpcxb);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        }else if (position == 6){
            img.setImageResource(R.mipmap.gyxlb);
            tv.setTextColor(mContext.getResources().getColor(R.color.tablayout_text_unselect));
        }

        return view;
    }
}
